<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="utf-8" />
  <!-- 引入刚刚下载的 ECharts 文件 -->
  <title>折线图</title>
  <script th:src="@{/static/echarts/echarts.min.js}"></script>
  <script th:src="@{/static/echarts/china.js}"></script>
  <script th:src="@{/static/echarts/jquery-1.11.1.min.js}"></script>
  <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}"  media="all">
  <script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
</head>

<body>

          <div id="main" style="width: 800px;height:400px;top:50%;left:20%;margin-left: -100px;margin-top: 60px;text-align:center;"></div>



<script type="text/javascript">

  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('main'));

  var dataList = [];

  option = {
    title: {
      text: 'Stacked Line'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['确诊人数', '隔离人数', '治愈人数', '死亡人数', '疑似人数']
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    toolbox: {
      feature: {
        saveAsImage: {}
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },

  };

  // 发送ajax请求
  $.ajax({
    // 发送请求的地址
    url:'/queryLine',
    // 返回的数据类型
    dataType: "json",
    success: function (data){
       //data:map<cityList[],dataList[]>
      //某种意义上来说，数组也是object map<cityList[],dataList[]>

      myChart.setOption({
        series: [
          {
            name: '确诊人数',
            type: 'line',
            stack: 'Total',
            data: data.confirmList
          },
          {
            name: '隔离人数',
            type: 'line',
            stack: 'Total',
            data: data.isolationList
          },
          {
            name: '治愈人数',
            type: 'line',
            stack: 'Total',
            data: data.cureList
          },
          {
            name: '死亡人数',
            type: 'line',
            stack: 'Total',
            data: data.deadList
          },
          {
            name: '疑似人数',
            type: 'line',
            stack: 'Total',
            data: data.similarList
          }
        ]
      })
    }
  });

  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);


</script>

</body>
</html>